home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_3.5 / Examples / Printer / HP_DeskJet_CMYK / dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-30  |  8.2 KB  |  381 lines

  1. /*
  2.  * $Id: dospecial.c 44.4 1999/09/13 13:37:33 olsen Exp olsen $
  3.  *
  4.  * :ts=4
  5.  *
  6.  * COPYRIGHT:
  7.  *
  8.  *   Unless otherwise noted, all files are Copyright (c) 1999 Amiga, Inc.
  9.  *   All rights reserved.
  10.  *
  11.  * DISCLAIMER:
  12.  *
  13.  *   This software is provided "as is". No representations or warranties
  14.  *   are made with respect to the accuracy, reliability, performance,
  15.  *   currentness, or operation of this software, and all use is at your
  16.  *   own risk. Neither Amiga nor the authors assume any responsibility
  17.  *   or liability whatsoever with respect to your use of this software.
  18.  *
  19.  */
  20.  
  21. #include "global.h"
  22.  
  23. /****************************************************************************/
  24.  
  25. #include "config.h"
  26.  
  27. /****************************************************************************/
  28.  
  29. /* This table will be used to translate ISO colours
  30.  * into PCL colours.
  31.  */
  32. STATIC UBYTE ColourTable[10] =
  33. {
  34.     /* 0 = black */        1,
  35.     /* 1 = red */        12,
  36.     /* 2 = green */        10,
  37.     /* 3 = yellow */    8,
  38.     /* 4 = blue */        6,
  39.     /* 5 = magenta */    4,
  40.     /* 6 = cyan */        2,
  41.     /* 7 = white */        0,
  42.     /* 8 = NC */        1,    /* make it black */
  43.     /* 9 = default */    1    /* we use black */
  44. };
  45.  
  46. /****************************************************************************/
  47.  
  48. LONG __stdargs __saveds
  49. DoSpecial(
  50.     UWORD *    command,
  51.     UBYTE    output_buffer[],
  52.     BYTE *    current_line_position,
  53.     BYTE *    current_line_spacing,
  54.     BYTE *    crlf_flag,
  55.     UBYTE    params[])
  56. {
  57.     STATIC LONG text_length,top_margin;
  58.  
  59.     LONG lines_per_inch;
  60.     LONG page_size;
  61.     LONG page_format;
  62.     LONG pitch;
  63.     LONG print_quality;
  64.     LONG result = 0;
  65.     LONG colour;
  66.  
  67.     switch((*command))
  68.     {
  69.         /* Initialize */
  70.         case aRIN:
  71.  
  72.             /* Tell the printer what size paper to use. */
  73.             if(PD->pd_Preferences.PrintSpacing == EIGHT_LPI)
  74.                 lines_per_inch = 8;
  75.             else
  76.                 lines_per_inch = 6;
  77.  
  78.             /* NOTE: paper sizes are one inch smaller than the
  79.              *       real page size to account for the size of
  80.              *       the printable page area.
  81.              */
  82.             switch(PD->pd_Preferences.PaperSize)
  83.             {
  84.                 case US_LETTER:
  85.  
  86.                     page_size = 10 * lines_per_inch;
  87.                     page_format = 2;
  88.                     break;
  89.  
  90.                 case US_LEGAL:
  91.  
  92.                     page_size = 13 * lines_per_inch;
  93.                     page_format = 3;
  94.                     break;
  95.  
  96.                 case EURO_A3:
  97.  
  98.                     page_size = 16 * lines_per_inch;
  99.                     page_format = 27;
  100.  
  101.                     break;
  102.  
  103.                 case EURO_A4:
  104.  
  105.                     page_size = 11 * lines_per_inch;
  106.                     page_format = 26;
  107.  
  108.                     break;
  109.  
  110.                 default:
  111.  
  112.                     page_size = 0;
  113.                     page_format = 0;
  114.  
  115.                     break;
  116.             }
  117.  
  118.             /* Select the page format and pick the right
  119.              * page length. For the CUSTOM paper size,
  120.              * don't set the page format.
  121.              */
  122.             if(page_size != 0)
  123.             {
  124.                 SPrintf(output_buffer,
  125.                     "\033&l"    /* select page size and format */
  126.                     "%ldA",        /* page format */
  127.                     page_format);
  128.  
  129.                 text_length = page_size;
  130.             }
  131.             else
  132.             {
  133.                 strcpy(output_buffer,"");
  134.  
  135.                 text_length = PD->pd_Preferences.PaperLength;
  136.             }
  137.  
  138.             if(PD->pd_Preferences.PrintPitch == ELITE)
  139.                 pitch = 12;
  140.             else if (PD->pd_Preferences.PrintPitch == FINE)
  141.                 pitch = 15;
  142.             else
  143.                 pitch = 10;
  144.  
  145.             if(PD->pd_Preferences.PrintQuality == LETTER)
  146.                 print_quality = 2;
  147.             else
  148.                 print_quality = 1;
  149.  
  150.             top_margin = 2;
  151.  
  152.             SPrintf(&output_buffer[strlen(output_buffer)],
  153.                 "\033&d@"        /* disable underline */
  154.                 "\033&l"        /* select page size and format */
  155.                 "%ldD"            /* number of lines per inch */
  156.                 "\033(0N"        /* primary font encoding = ISO 8859-1 */
  157.                 "\033(s"        /* begin font selection */
  158.                 "0b"            /* primary font stroke weight = medium */
  159.                 "%ldh"            /* primary pitch */
  160.                 "%ldq"            /* print quality */
  161.                 "0p"            /* primary spacing = fixed */
  162.                 "0s"            /* primary style = upright */
  163.                 "3t"            /* primary font = courier */
  164.                 "0u"            /* font placement = normal */
  165.                 "12V"            /* point size = 12 */
  166.                 "\r"            /* return to start of line (carriage return) */
  167.                 "%s"            /* select text colour */
  168.                 "\033&l"        /* select page size and format */
  169.                 "1l"            /* enable perforation skip */
  170.                 "%lde"            /* set top margin */
  171.                 "%ldF"            /* set text length */
  172.                 "\033&a"        /* set horizontal margins */
  173.                 "%ldl"            /* set left margin */
  174.                 "%ldM"            /* set right margin */
  175.                 "\r",            /* return to start of line (carriage return) */
  176.                 lines_per_inch,
  177.                 pitch,
  178.                 print_quality,
  179.                 (CONFIG_SUPPORTS_COLOR) ? "\033*r-4U\033*v1S" : "", /* select black text */
  180.                 top_margin,
  181.                 text_length,
  182.                 MAX(1,PD->pd_Preferences.PrintLeftMargin) - 1,
  183.                 MAX(1,PD->pd_Preferences.PrintRightMargin) - 1);
  184.  
  185.             result = strlen(output_buffer);
  186.             break;
  187.  
  188.         /* Set left and right margins */
  189.         case aSLRM:
  190.  
  191.             SPrintf(output_buffer,
  192.                 "\033&a"                /* set horizontal margins */
  193.                 "%ldl"                    /* set left margin */
  194.                 "%ldM"                    /* set right margin */
  195.                 "\r",                    /* return to start of line (carriage return) */
  196.                    MAX(1,params[0]) - 1,    /* left margin */
  197.                    MAX(1,params[1]) - 1);    /* right margin */
  198.  
  199.             result = strlen(output_buffer);
  200.             break;
  201.  
  202.         /* Superscript on */
  203.         case aSUS2:
  204.  
  205.             if((*current_line_position) == 0) /* Vertical position == normal? */
  206.             {
  207.                 /* Partial line up */
  208.                 (*command) = aPLU;
  209.                 (*current_line_position) = 1;
  210.             }
  211.             else if((*current_line_position) < 0) /* Vertical position == lowered? */
  212.             {
  213.                 /* Reverse line feed */
  214.                 (*command) = aRI;
  215.                 (*current_line_position) = 1;
  216.             }
  217.  
  218.             break;
  219.  
  220.         /* Superscript off */
  221.         case aSUS1:
  222.  
  223.             if((*current_line_position) > 0) /* Vertical position == raised? */
  224.             {
  225.                 /* Partial line down */
  226.                 (*command) = aPLD;
  227.                 (*current_line_position) = 0;
  228.             }
  229.  
  230.             break;
  231.  
  232.         /* Subscript on */
  233.         case aSUS4:
  234.  
  235.             if((*current_line_position) == 0) /* Vertical position == normal? */
  236.             {
  237.                 /* Partial line down */
  238.                 (*command) = aPLD;
  239.                 (*current_line_position) = -1;
  240.             }
  241.             else if ((*current_line_position) > 0) /* Vertical position == raised? */
  242.             {
  243.                 /* Line feed */
  244.                 (*command) = aIND;
  245.                 (*current_line_position) = -1;
  246.             }
  247.  
  248.             break;
  249.  
  250.         /* Subscript off */
  251.         case aSUS3:
  252.  
  253.             if((*current_line_position) < 0) /* Vertical position = lowered? */
  254.             {
  255.                 /* Partial line up */
  256.                 (*command) = aPLU;
  257.                 (*current_line_position) = 0;
  258.             }
  259.  
  260.             break;
  261.  
  262.         /* Normalize the line */
  263.         case aSUS0:
  264.  
  265.             if((*current_line_position) > 0) /* raised */
  266.                 (*command) = aPLD;    /* Partial line down */
  267.             else if ((*current_line_position) < 0) /* lowered */
  268.                 (*command) = aPLU;    /* Partial line up */
  269.  
  270.             (*current_line_position) = 0;
  271.  
  272.             break;
  273.  
  274.         /* Partial line up. */
  275.         case aPLU:
  276.  
  277.             (*current_line_position)++;
  278.             break;
  279.  
  280.         /* Partial line down */
  281.         case aPLD:
  282.  
  283.             (*current_line_position)--;
  284.             break;
  285.  
  286.         /* Set top and bottom margins. */
  287.         case aSTBM:
  288.  
  289.             if(params[0] == 0)
  290.                 params[0] = top_margin;
  291.             else
  292.                 top_margin = params[0] - 1;
  293.  
  294.             if(params[1] == 0)
  295.                 params[1] = text_length;
  296.             else
  297.                 text_length = params[1];
  298.  
  299.             SPrintf(output_buffer,
  300.                 "\033&l"                /* select page size and format */
  301.                 "%lde"                    /* set top margin */
  302.                 "%ldF",                    /* set text length */
  303.                 params[0],                /* top margin */
  304.                    params[1] - params[0]);    /* text length */
  305.  
  306.             result = strlen(output_buffer);
  307.             break;
  308.  
  309.         /* Set form length */
  310.         case aSLPP:
  311.  
  312.             /* Restore text length and top margin. */
  313.  
  314.             SPrintf(output_buffer,
  315.                 "\033&l"        /* select page size and format */
  316.                 "%lde"            /* set top margin */
  317.                 "%ldF",            /* set text length */
  318.                 top_margin,
  319.                    text_length);
  320.  
  321.             result = strlen(output_buffer);
  322.             break;
  323.  
  324.         /* Reset */
  325.         case aRIS:
  326.  
  327.             PD->pd_PWaitEnabled = 253;
  328.             break;
  329.  
  330.         /* Select foreground colour */
  331.         case aSFC:
  332.  
  333.             if(CONFIG_SUPPORTS_COLOR)
  334.             {
  335.                 if(PD->pd_Preferences.PrintShade == SHADE_COLOR)
  336.                 {
  337.                     if (params[0] < 30)
  338.                         colour = 30;
  339.                     else if (params[0] > 39)
  340.                         colour = 39;
  341.                     else
  342.                         colour = params[0];
  343.                 }
  344.                 else
  345.                 {
  346.                     /* If not in colour mode, use the
  347.                      * default foreground colour.
  348.                      */
  349.                     colour = 39;
  350.                 }
  351.  
  352.                 SPrintf(output_buffer,
  353.                     "\033*r-4U"
  354.                     "\033*v%ldS",
  355.                        ColourTable[colour - 30]);
  356.  
  357.                 result = strlen(output_buffer);
  358.             }
  359.  
  360.             break;
  361.     }
  362.  
  363.     return(result);
  364. }
  365.  
  366. /****************************************************************************/
  367.  
  368. LONG __stdargs __saveds
  369. ConvFunc(
  370.     UBYTE *    buf,
  371.     UBYTE    c,
  372.     LONG    crlf_flag) /* expand lf into lf/cr flag (0-yes, else no ) */
  373. {
  374.     if(c == '\f') /* if formfeed (page eject) */
  375.         PED->ped_PrintMode = 0; /* no data to print */
  376.     else if (c > ' ')
  377.         PED->ped_PrintMode = 1; /* alpha data has been sent */
  378.  
  379.     return(-1); /* pass all chars back to the printer device */
  380. }
  381.